/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.continew.admin.content.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.continew.admin.content.model.resp.ContentResp;
import top.continew.admin.content.model.resp.EventStatisticsResp;
import top.continew.admin.content.model.resp.EventTitleResp;
import top.continew.admin.content.model.resp.MonthStatisticsResp;
import top.continew.starter.data.mp.base.BaseMapper;
import top.continew.admin.content.model.entity.ContentDO;
import top.continew.starter.extension.datapermission.annotation.DataPermission;

import java.util.List;

/**
 * 内容 Mapper
 *
 * @author floyd
 * @since 2024/11/15 14:55
 */
public interface ContentMapper extends BaseMapper<ContentDO> {

    /**
     * 分页查询列表
     *
     * @param page         分页条件
     * @param queryWrapper 查询条件
     * @return 分页列表信息
     */
    @DataPermission(tableAlias = "t1")
    IPage<ContentResp> selectContentPage(@Param("page") IPage<ContentDO> page,
                                         @Param(Constants.WRAPPER) QueryWrapper<ContentDO> queryWrapper);

    /**
     * 查询列表
     *
     * @param queryWrapper 查询条件
     * @return 列表信息
     */
    @DataPermission(tableAlias = "t1")
    List<ContentResp> selectContenList(@Param(Constants.WRAPPER) QueryWrapper<ContentDO> queryWrapper);

    /**
     * 查询公司大事记信息
     *
     * @return 查询公司大事记信息
     */
    @Select("SELECT DATE_FORMAT( news_time, '%Y' ) AS eventYear,DATE_FORMAT( news_time, '%Y-%m' ) AS eventMonth,title FROM bsc_content WHERE category_id = (SELECT id FROM bsc_category WHERE NAME = '公司大事记' LIMIT 1)")
    List<EventTitleResp> eventStatistics();

    /**
     * 统计年份数据
     */
    @Select("SELECT DATE_FORMAT( news_time, '%Y' ) AS eventYear FROM  bsc_content WHERE category_id = (SELECT id FROM bsc_category WHERE NAME = '公司大事记' LIMIT 1) GROUP BY DATE_FORMAT( news_time, '%Y' )")
    List<EventStatisticsResp> yearStatistics();

    /**
     * 统计月份数据
     */
    @Select("SELECT DATE_FORMAT( news_time, '%Y' ) AS yearNumber,DATE_FORMAT( news_time, '%Y-%m' ) AS eventMonth FROM  bsc_content WHERE category_id = (SELECT id FROM bsc_category WHERE NAME = '公司大事记' LIMIT 1) GROUP BY DATE_FORMAT( news_time, '%Y' ),DATE_FORMAT( news_time, '%Y-%m' )")
    List<MonthStatisticsResp> monthStatistics();

    /**
     * 统计年份数据
     */
    @Select("SELECT DATE_FORMAT( news_time, '%Y' ) AS yearStr,DATE_FORMAT( news_time, '%Y-%m' ) AS monthStr,title FROM bsc_content WHERE category_id = (SELECT id FROM bsc_category WHERE NAME = '公司大事记' LIMIT 1)")
    List<EventTitleResp> titleStatistics();
}